/* 点击搜索弹出框并遮罩显示 */
var search = document.querySelector(".search");
var searchmask = document.querySelector(".searchmask");
var search_ipt = document.querySelector(".search_ipt")
function showSearch() {
    search.style.height = 300 + "px";
    search_ipt.style.display = "block";
    searchmask.style.display = "block";
}
function delBtn() {
    search.style.height = 0 + "px";
    search_ipt.style.display = "none";
    searchmask.style.display = "none";
}
function searchBtn() {
    //点击搜索按钮调转页面
    location.href = "../html/allgoods.html";
}

/* 设置轮播图 轮播到深色导航图片变色 */
var swiperActive = document.querySelector(".swiper-slide-active");
var header=document.querySelector("header");
var nav=document.querySelector(".nav");
var changeimg=document.querySelector(".chageimg");
var nava=document.querySelector(".nava");
var headnava=document.querySelector(".headnav a");
var swiper1 = new Swiper('#swiper1', {
    loop: true, // 循环模式选项
    autoplay: true,
    speed:5000,
    autoplay: {
        delay: 3000, //自动切换的时间间隔，单位ms
        disableOnInteraction: false //用户操作swiper之后，是否禁止autoplay    
    },
    //轮播开始的时候
    on:{
        transitionStart: function(swiper){
            //非loop下
            // console.log("acti"+this.activeIndex);
            //在loop下使用
            // console.log("rell"+this.realIndex);
            if(this.realIndex==1){
                header.style.color="#fff";
                nav.style.color="#fff";
                nava.style.color="#fff";
                headnava.style.color="#fff";
                //给图片添加类名
                changeimg.classList.toggle("name")    
            }else{
                header.style.color="#000";
                nav.style.color="#000";
                nava.style.color="#000";
                headnava.style.color="#000";
                changeimg.classList.remove("name")    
            }
          },
    }

})
/* 导航 */
/* 二级列表点击显示再次点击隐藏 */
var ulbtn=document.querySelectorAll(".ulbtn");
var ulnav=document.querySelectorAll(".ulnav");
var page=0;
ulbtn.forEach(function(libtn,i){
    var n=0;
    libtn.onclick=()=>{
        if(n==0){
            ulnav[i].style.display="block";
        n=1;
        }else{
            ulnav[i].style.display="none";
            n=0;
        }
        ulnav.forEach(function(v,j){
            if(i!=j){
                v.style.display="none";
                n=0;
            }
        })
        page=i;
    }

})

/* 购物袋 */
var bag=document.querySelector(".bag");
var car=document.querySelector(".car");
var pont=document.querySelector(".pont");
bag.onmousemove=function(){
    car.style.display="block";
    pont.style.display="none";
}
car.onmouseleave=function(){
    car.style.display="none"
    pont.style.display="block";
}
var carbtn=document.querySelector(".car button");
var uid=localStorage.getItem("username");
if(!uid){
    carbtn.onclick=function(){
        location.href="../html/allgoods.html";
    }
}


/* 登录 */
var login_mask=document.querySelector(".login_mask");
var login_else=document.querySelector(".login_else");
function userLogin(){
    login_mask.style.display="block";
    document.body.style.overflowY="hidden";
    pont.style.display="none";
}
login_else.onclick=function(){
    login_mask.style.display="none";
    pont.style.display="block";
    document.body.style.overflowY="unset";
}
/* 登录ajax */
var signipt=document.querySelectorAll(".login input");
var signbtn=document.querySelector(".login button");
var prompt=document.querySelector(".prompt");
/* 正则判断 */
var isname=0;
signipt[0].onkeyup=function(){
    var res=/^(\w|[\u2E80-\u9FFF]){3,6}$/.test(signipt[0].value);
    if(res){
        isname=1;        
    }else{
        isname=0;
    }
}
var ispassword=0;
signipt[1].onkeyup=function(){
    var res=/^\w{6,12}$/.test(signipt[1].value);
    if(res){
        ispassword=1;
    }else{
        ispassword=0;
    }
}
signbtn.onclick=function(){
    if(isname==1&&ispassword==1){
        var username=signipt[0].value;
        var password=signipt[1].value;
        axios.get(SignApi,{params:{username,password}}).then(function(res){
            console.log(res.data);
            if(res.data.code==0){
                signipt[1].nextElementSibling.innerHTML=res.data.msg;
                prompt.style.display="block";
            }else{
                alert("登录成功");
                localStorage.setItem("username",JSON.stringify(signipt[0].value));
                localStorage.setItem("password",JSON.stringify(signipt[1].value));
                location.reload();
            }
        })
    }else{
        signipt[1].nextElementSibling.innerHTML="请检查用户或密码";
        prompt.style.display="block";
    }
}
/* 显示账户 */
var urname=JSON.parse(localStorage.getItem("username"));
var namespan=document.querySelector(".namespan");
var account=document.querySelector(".account");
var addname=document.querySelector(".addname");
if(urname){
    account.style.display="none";
    namespan.style.display="inline-block";
    addname.innerHTML=urname;
    function exitName(){
        namespan.style.display="none";
        account.style.display="inline-block";
        localStorage.removeItem("username");
        localStorage.removeItem("password");
    }

}else{
    namespan.style.display="none";
    account.style.display="inline-block";
}

/* 指引 */
var up=document.querySelector(".up");
up.onclick=function(){
    document.documentElement.scrollTop=0;
}
/* 轮播2 */
var swiper2 = new Swiper('#swiper2', {
    slidesPerView: 3,
    spaceBetween: 20,
    centeredSlides: true,
    loop: true,
    autoplay: true,
    autoplay: {
        disableOnInteraction: false //用户操作swiper之后，是否禁止autoplay    
    },
    speed: 4000,
    pagination: {
      el: '.swiper-pagination',
      clickable: true,
    },
  });
/* 轮播3 */
  var swiper3= new Swiper('#swiper3', {
    loop: true, // 循环模式选项
    autoplay: true,
    speed: 4000,
    autoplay: {
        delay: 2000, //自动切换的时间间隔，单位ms
        disableOnInteraction: false //用户操作swiper之后，是否禁止autoplay    
    },
})
/* 二维码 */
var chatimg=document.querySelector(".chatimg img");
var ewm=document.querySelector(".ewm");
ewm.onmousemove=function(){
    chatimg.style.display="block";
}
ewm.onmouseleave=function(){
    chatimg.style.display="none";
}

